<?php

itstock_structure($structure, 'software_location');
itstock_structure($Software, 'software');
$edit = false;
$edit2 = false;

if(isset($_POST['soft_id'])) {
  $Software['where'][0] = 'software.id='.itstock_decode($_POST['soft_id']);
}

if(isset($_POST['id'])){
  $structure['where'][0] = sprintf("`%s`.`id`='%s'", $structure['table'], itstock_decode($_POST['id']));
  $edit = itstock_search_all($structure);
  $Software['where'][0] = 'software.id='.$structure['data'][0]['software_id'];
}

$edit2 = itstock_search_all($Software);

?><b><?php echo (!$edit?'':'Assign ')?>Software</b>
  <br><br><br>
  <p class="error" id="e_msg" style="display: none;"></p>
<form class="save" action="store.php?type=software_location" method="POST" id="form_software_location" autocomplete="off">
  <input type="hidden" value="<?php echo ($edit?itstock_encode($structure['data'][0]['id']):'')?>" id="id" name="id">
  <input type="hidden" value="<?php echo ($edit2?itstock_encode($Software['data'][0]['id']):'')?>" id="software_id" name="software_id">
  <table>
     <table>
    <tr>
      <td><label>Vendor:</label></td>
      <td><?php echo ($edit2?$Software['data'][0]['vendor']:'')?></td>
    </tr>
    <tr>
      <td><label>Product:</label></td>
      <td><?php echo ($edit2?$Software['data'][0]['product']:'')?></td>
    </tr>
       <tr>
      <td><label>Version:</label></td>
      <td><?php echo ($edit2?$Software['data'][0]['version']:'')?></td>
    </tr>
    <tr>
      <td><label>Serial Number:</label></td>
      <td><?php echo ($edit2?$Software['data'][0]['serialns']:'')?></td>
    </tr>
    <tr>
      <td><label>Building:</label></td>
      <td>
        <span id="location_building"><?php
          $structure['data'][1] = &$structure['data'][0];
        if($edit) {
          echo $structure['data'][1]['building'];
        } else {
          echo '<span style="color: #FF0000;">Not Set</span>';
        }
        ?></span>
        <input type="hidden" value="<?php echo ($edit?itstock_encode($structure['data'][0]['cpu_id']):'');?>" id="cpu_id" name="cpu_id">
        <input type="text" value="<?php echo $edit?'1':'';?>" style="display:none;" id="location_set" required>
        <img onclick="itstock_locations('cpus');" src="img/search.png" title="Set Location" style="float:right;" />
      </td>
    </tr>
    <tr>
      <td><label>Department:</label></td>
      <td><span id="location_department"><?php echo $edit?$structure['data'][1]['department']:'';?></span></td>
    </tr>
    <tr>
      <td><label>Floor:</label></td>
      <td><span id="location_floor"><?php echo $edit?$structure['data'][1]['floor']:'';?></span></td>
    </tr>
    <tr>
      <td><label>Spot:</label></td>
      <td><span id="location_spot"><?php echo $edit?$structure['data'][1]['spot']:'';?></span></td>
    </tr>
    <tr>
      <td><label>Name:</label></td>
      <td><span id="location_location"><?php echo $edit?$structure['data'][1]['location']:'';?></span></td>
    </tr>
    <tr>
      <td><label>Case:</label></td>
      <td><span id="location_cpu"><?php echo $edit?$structure['data'][1]['cpu']:'';?></span></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><br><input type="submit" value="Save" style="margin-right: 100px;"><input type="reset" value="Reset"></td>
    </tr>
  </table>
</form>
